{{- $comment := .Site.Params.comment}}
{{- if eq $comment.type "valine"}}
<script src="https://cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/valine"></script>
<script type="text/javascript">
    var GUEST = ['nick', 'mail', 'link'];
    var meta = '{{- $comment.valine.meta }}';
    meta = meta.split(',').filter(function (item) {
        return GUEST.indexOf(item) > -1;
    });
    new Valine({
        el: '#vcomments',
        verify: {{- $comment.valine.verify }},
        notify: {{- $comment.valine.notify }},
        appId: '{{- $comment.valine.appid }}',
        appKey: '{{- $comment.valine.appkey }}',
        placeholder: '{{- $comment.valine.placeholder }}',
        avatar: '{{- $comment.valine.avatar }}',
        meta: meta,
        pageSize: '{{- $comment.valine.pageSize }}' || 10,
        visitor: {{- $comment.valine.visitor }}
});
</script>
{{- else if eq $comment.type "disqus" }}
<script defer>
    var disqus_config = function () {
        this.page.url = '{{- .Permalink }}';
        this.page.identifier = '{{- $comment.disqus }}';
    };
    (function () {
        var d = document, s = d.createElement('script');
        s.src = '//' + '{{- $comment.disqus }}' + '.disqus.com/embed.js';
        s.setAttribute('data-timestamp', +new Date());
        (d.head || d.body).appendChild(s);
    })();
</script>
{{- else if eq $comment.type "gitalk" }}
<!-- <link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css"> -->
<script src="https://cdn.jsdelivr.net/npm/gitalk@1.4.0/dist/gitalk.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/blueimp-md5@2.10.0/js/md5.min.js"></script>
<script type="text/javascript">
    var gitalk = new Gitalk({
        clientID: '{{- $comment.gitalk.ClientID }}',
        clientSecret: '{{- $comment.gitalk.ClientSecret }}',
        repo: '{{- $comment.gitalk.repo }}',
        owner: '{{- $comment.gitalk.owner }}',
        admin: ['{{- $comment.gitalk.admin }}'],
        id: md5(location.pathname),
        distractionFreeMode: true
    });
    gitalk.render('comments');
</script>
{{- end }}